Skip to content

feat(peer_manager): track LastAction and LastDisconnect on PeerInfo#27

Draft
barnabasbusa wants to merge 1 commit into
grandinetech:mainfrom
barnabasbusa:bbusa/peer-scores-beacon-api
Draft

feat(peer_manager): track LastAction and LastDisconnect on PeerInfo#27
barnabasbusa wants to merge 1 commit into
grandinetech:mainfrom
barnabasbusa:bbusa/peer-scores-beacon-api

Conversation

@barnabasbusa
Copy link
Copy Markdown

Summary

Adds LastAction and LastDisconnect tracking to PeerInfo, mirroring the pattern from upstream Lighthouse's bbusa/peer-scores-last-event branch (also a draft). Used by grandinetech/grandine#NNN to expose peer-scoring fields on /eth/v1/node/peers per a simplified beacon-API spec extension (ethereum/beacon-APIs#606).

What's in this PR

  1. peer_manager/peerdb/score.rs — new LastAction, LastDisconnect, DisconnectDirection types + serialize_instant_seconds_ago helper. PeerAction and ReportSource made Serialize + Clone + Copy for downstream use.
  2. peer_manager/peerdb/peer_info.rslast_action/last_disconnect fields + accessors last_action() / last_disconnect() and setters.
  3. peer_manager/peerdb.rsrecord_last_disconnect() method; report_peer() updated to populate LastAction with pre/post-score delta.
  4. peer_manager/mod.rsrpc_error_msg() (per-RPCError granular tags, with Grandine-specific SszReadError / SszWriteError variants) and goodbye_reason_name(). goodbye_peer() records LastDisconnect{direction: Sent}.
  5. service/mod.rsRequestType::Goodbye handler calls record_last_disconnect() with DisconnectDirection::Received.

Spec proposal

ethereum/beacon-APIs#606

Coordinated implementations

Part of a coordinated multi-client effort.

Status

Draft. Builds clean as part of cargo build -p grandine --features default-networks.

Adds two optional fields to PeerInfo:

- last_action: { reason, source, action, delta, seconds_ago }
  populated from PeerDB::report_peer (skipped for trusted peers)
- last_disconnect: { reason, code, direction, seconds_ago }
  populated from PeerManager::goodbye_peer (direction=sent) and
  the inbound goodbye handler in service/mod.rs (direction=received)

Also replaces the single "handle_rpc_error" report-peer msg with
rpc_error_msg() which maps each RPCError variant (and inner
RpcErrorResponse code) to a stable static tag:
rpc_incomplete_stream, rpc_invalid_data, rpc_ssz_decode_error,
rpc_io_error, rpc_negotiation_timeout, rpc_stream_timeout,
rpc_unsupported_protocol, rpc_unknown_status,
rpc_resource_unavailable, rpc_server_error, rpc_invalid_request,
rpc_rate_limited, rpc_blobs_not_found.

Both fields use #[serde(skip_serializing_if = "Option::is_none")]
so they only appear after the first relevant event, keeping the
existing JSON shape backwards-compatible.

Lets external tooling display per-peer downscore reasons across
clients without scraping logs or Prometheus.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant